package com.zz.course.params;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.lang.reflect.Method;

public class DataProviderTest {


    @Test(dataProvider = "sourceData")
    public void paramter01 (String userName, String password) {
        System.out.println("username: " + userName + " pw: " + password);
    }

    @DataProvider(name = "sourceData")
    public Object[][] prodiderData(){
        Object [][] obj = new Object[][]{
                {"zhangsan", "123456"},
                {"lisi", "666"},
                {"wangwu", "888"},
                {"zhaoliu", "9999"}
        };
        return obj;
    }

    @Test(dataProvider = "methodData")
    public void case01(String name, Integer age){
        System.out.println("name: " + name + " age: " + age);
    }

    @Test(dataProvider = "methodData")
    public void case02(String name, String pw){
        System.out.println("name: " + name + " pw: " + pw);
    }

    @DataProvider(name = "methodData")
    public Object[][] provider(Method method){
        Object[][] obj = null;

        if("case01".equals(method.getName())){
            obj = new  Object[][]{
                    {"zhangsan", 23},
                    {"lisi", 24},
                    {"wangwu", 25},
                    {"zhaoliu", 26}
            };
        }

        if("case02".equals(method.getName())){
            obj = new  Object[][]{
                    {"zhangsan", "123456"},
                    {"lisi", "666"},
                    {"wangwu", "888"},
                    {"zhaoliu", "9999"}
            };
        }
        return obj;
    }


}
